#!/bin/bash -e

while getopts  "h" opt; do
	case  $opt  in
        h) echo `basename $0` '[path]' && exit 1;;
	esac
done
shift $(($OPTIND - 1))

# if [ $# -lt 1 ]; then echo `basename $0` path; exit 1; fi
if [ $# -lt 1 ]; then pwd; exit 1; fi
if test "$1" == .; then pwd; exit 0; fi
if test "$1" == ..; then dirname $(pwd); exit 0; fi

# if test ! -e "$1"; then echo Error: $1 no exists. >&2 && exit 1; fi # exam if file exists.

file=$(echo $1|sed 's/\/$//') # discard / in the end of the string

if
echo $file |grep '^\/' # absolute path
then
:
else # relative path
	path=$(pwd)/$file # a absolute path
	dir=$(dirname $path) # get path dir
	base=$(basename $path) # get file name
	
	cd $dir # for getting a standard path
	
	if test "$(pwd)" = "/"; then # path is /
	echo /
	else
	echo $(pwd)/$base # a standard absolute path
	fi

	
fi



# :<<last
# if
# echo $1 |grep '^/' >/dev/null
# then
# echo $1
# else
	# path=`pwd $1`/$1
	
	# if
	# cd $(dirname $path) && pwd|grep '/$' >/dev/null
	# then
	# echo /$(basename $path)
	# else
	
# fi

# last